package day02;

public class DataTypeDemo {
    public static void main(String[] args) {
        byte b1 = 5;
        byte b2 = 6;
        byte b3 = (byte) (b1+b2);

        System.out.println(2+2); //4
        System.out.println(2+'2'); //52
        System.out.println('2'+'2'); //100
        System.out.println('2'); //2

        int a = '我';
        System.out.println(a);
        char b = 65;
        System.out.println(b); //A

        /*
        //类型间的转换
        int a = 5;
        long b = a; //自动/隐式类型转换
        int c = (int) b; //强制类型装换

        long d = 5; //自动类型转换
        double e = 5; //自动类型转换
        System.out.println(e); //5.0

        long f = 10000000000L;
        int g = (int) f;
        System.out.println(g); //1410065408,强转有可能发生溢出

        double h = 25.678;
        int i = (int) h;
        System.out.println(i); //25,强转可能会丢失精度
        */

        /*
        //5)char:字符型，2个字节
        char c1 = '女';
        char c2 = 'f';
        char c3 = '6';
        char c4 = ' ';

        char c8 = 64846;
        System.out.println(c8);

        char c9 = '\\';
        System.out.println(c9);
        */

        /*
        //4)boolean:布尔型，1个字节
        boolean a = true; //true为布尔型直接量
        boolean b = false; //false为布尔型直接量
         */

        /*
        //3)double:浮点型，8个字节
        double a = 25.678;
        float b = 25.678F;

        double c=3.0,d=2.9;
        System.out.println(c-d); //0.10000000000000009,发生舍入误差
        */

        /*
        //2)long:长整型,8个字节，-900万万亿多到900万万亿多
        long a = 25L; //长整型直接量
        //long b = 10000000000; //编译错误，100亿默认为int类型，但超出范围
        long c = 10000000000L;

        long e = 1000000000*2*10L;
        System.out.println(e); //200亿
        long f = 1000000000*3*10L;
        System.out.println(f); //不是300亿
        long g = 1000000000L*3*10;
        System.out.println(g); //300亿
         */

        /*
        //1)int:整形，4个字节，-2147483648到2147483647
        int a = 250;

        System.out.println(5/2);

        int d = 2147483647; //int的最大值
        d = d+1;
        System.out.println(d); //-2147483648,发生溢出
         */
    }
}
